package com.hcy.controller.customer;

import com.hcy.customer.CarLevelInfoRequest;
import com.hcy.customer.CarLevelInfoResponse;
import com.hcy.customer.CustomerRuntimeBz;
import com.hcy.rabbitbasicmodel.enums.Code;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author huchenying
 * @Description
 * @Date 2022/3/11 19:23
 */
@RestController
@RequestMapping("/customer/runtime")
public class RuntimeController {

    static final Logger logger = LoggerFactory.getLogger(RuntimeController.class);

    @Autowired
    private CustomerRuntimeBz customerRuntimeBz;

    /**
     * @Author huchenying
     * @Description 获得车辆类型和价格信息
     * @Date 2022/3/11 19:30
     **/
    @PostMapping("/getCarInfo")
    public ResponseData<List<CarLevelInfoResponse>> getCarInfo(@Validated @RequestBody CarLevelInfoRequest request){
        logger.info("getCarInfo start");
        ResponseData<List<CarLevelInfoResponse>> responseData = new ResponseData<>();
        try {
            List<CarLevelInfoResponse> response = customerRuntimeBz.getCarLevelInfo(request);
            responseData.setData(response);
            responseData.setCode(Code.Success);
            return responseData;
        } catch (Exception e) {
            logger.error("getCarInfo error -> {}", ToStringBuilder.reflectionToString(e));
            responseData.setCode(Code.Fail);
            return responseData;
        }
    }
}
